import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { ClockManager } from "../manager/ClockManager";
import { TimeEvent } from "../events/TimeEvent";
import { DataEvent } from "../events/DataEvent";
import { ParamsConst } from "../../common/global/ParamsConst";
import { LinkIcon } from "../view/icon/LinkIcon";
//class IconController
    
    export  class IconController extends Controller
    {
       

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.onLoginSuccess);
            ClockManager.instance.addEventListener(TimeEvent.ServerOpenDayChange, this.onServerOpenDayChangeHandler);
            return;
        }

        /* internal  */onLoginSuccess(arg1: DataEvent): void
        {
            this.checkLinkUrl();
            this.checkNewServerIcon();
            return;
        }

        /* internal  */onServerOpenDayChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.checkNewServerIcon();
            return;
        }

        /* internal  */checkLinkUrl(): void
        {
            if (ParamsConst.instance.linkUrl) 
            {
                this.linkIcon.show();
            }
            else if (this._linkIcon) 
            {
                this._linkIcon.hide();
            }
            return;
        }

        /* internal  */checkNewServerIcon(): void
        {
            if (ParamsConst.instance.linkUrlNewServer && ClockManager.instance.serverOpenDateNum <= 7) 
            {
                this.linkIconNewServer.show();
            }
            else if (this._linkIconNewServer) 
            {
                this._linkIconNewServer.hide();
            }
            return;
        }

        public get linkIcon(): LinkIcon
        {
            if (!this._linkIcon) 
            {
                this._linkIcon = new LinkIcon();
                this._linkIcon.setLinkUrl(ParamsConst.instance.linkIcon, ParamsConst.instance.linkUrl);
            }
            return this._linkIcon;
        }

        public get linkIconNewServer(): LinkIcon
        {
            if (!this._linkIconNewServer) 
            {
                this._linkIconNewServer = new LinkIcon();
                this._linkIconNewServer.setLinkUrl(ParamsConst.instance.linkIconNewServer, ParamsConst.instance.linkUrlNewServer);
            }
            return this._linkIconNewServer;
        }

        private /* var */_linkIcon: LinkIcon;

        private /* var */_linkIconNewServer: LinkIcon;
    }
